<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<!DOCTYPE>
<html>
<head content="-找回密码">
    <%@ include file="/resources/modular/head/outside-head.jsp" %>
</head>
<body>
<div class="loading"></div>
<header class="header">找回密码</header>
<div class="page">
    <div class="resetpasswordpage">
        <p class="resetpassword_title">
            <em>账户设置</em>
            <span id="fogetpassowrd_point">请填写你的手机号、用户名用于找回密码</span></p>

        <form class="resetpassword_form">
            <p>
                <span><i>*</i>手机号</span>
                <input class="resetpassword_tel" type="tel" placeholder="请输入手机号" required name="mobile">
                <i class="point">请正确输入手机号码</i></p>
            <p>
                <span><i>*</i>用户名</span>
                <input class="resetpassword_username" type="text" placeholder="请设置用户名" required name="username">
                <i class="point">请输入5-20位数字、字母或下划线</i></p>
            <p>
                <span><i>*</i>验证码</span>
                <input class="resetpassword_imagecode" type="text" placeholder="请输入验证码" required name="imgcode">
                <a class="resetpassword_imagecodeurl" href="javascript:;">
                    <img onclick="chageCode()" id="captchaImage" src="${basePath}v2/authCode" alt="验证码">
                    <span onclick="chageCode()">&nbsp;换一张</span></a>
                <i class="point">请正确输入验证码</i></p>
            <div class="resetpassword_hr"></div>
            <p>
                <span><i>*</i>验证码</span>
                <input class="resetpassword_telcode" type="text" placeholder="请输入短信验证码" required name="smscode">
                <a class="resetpassword_telcodeurl" href="javascript:;">获取短信验证码</a>
                <i class="point">请正确输入短信验证码</i></p>
            <div class="resetpassword_hr" style="margin-top:20px;"></div>
            <p>
                <span><i>*</i>登录密码</span>
                <input class="resetpassword_setpassword" type="password" placeholder="请设置登录密码" required name="">
                <i class="point">请输入6-18位数字、字母或下划线</i></p>
            <p>
                <span><i>*</i>确认密码</span>
                <input class="resetpassword_password" type="password" placeholder="请再次输入登录密码" required name="">
                <i class="point">您两次输入的密码不一致</i></p>

            <input type="hidden" name="password">

            <input style="margin-top:40px;" class="resetpassword_btn" type="button" value="确 认">
        </form>
    </div>
</div>

<div id="GC_childinfo_remove" class="login_common_pointpage_dv" style="display:none;" >
    <div class="login_common_pointpage">
        <p class="cur">恭喜,密码找回成功.</p>
        <div><a class="login_common_pointpagebtn" href="javascript:;" onclick="javascript:window.location = '${basePath}v2/login'">确认</a></div>
    </div>
</div>

</body>
</html>
<%@ include file="/resources/modular/foot/outside_footer.jsp" %>
<script type="text/javascript" src="${basePath}resources/js/v2/youyicloud-md5.js"></script>
<script>
    var regusername=/^\w{1,20}$/;
    var reguserpassword=/^[\w`~!@#\$%\^&\*\(\)_\+-=\[\]\\\{\}\|;':",\.\/<>\?]{6,18}$/;
    var regusertel=/^1[34578]\d{9}$/;
    /*更新图片验证码*/
    function chageCode() {
        $('#captchaImage').attr('src', '${basePath}v2/authCode?abc=' + Math.random());//链接后添加Math.random，确保每次产生新的验证码，避免缓存问题。
    }

    <%--获取短信验证码--%>
    function getsmscode() {
        $.ajax({
            url: '${basePath}v2/sms/sendfogetcode',
            type: 'POST',
            data: {
                "mobile": $(".resetpassword_tel").val(),
                "imgcode" : $(".resetpassword_imagecode").val()
            },
            error: function (response) {
                $errorMsg(response);
            },
            success: function (ret) {
                if (ret.result) {
                    alert(ret.info,"cur");
                } else {
                    if (ret.ERROR == "smscode") {
                        $(".resetpassword_telcodeurl~.point").text(ret.info).addClass("cur");
                    } else if (ret.ERROR == "imgcode") {
                        clearInterval(resettimer);
                        second=0;
                        $(".resetpassword_telcodeurl").text("获取短信验证码").removeClass("cur");
                        resetgetCaptcha();
                        $(".resetpassword_imagecode~.point").text(ret.info).addClass("cur");
                    } else if (ret.ERROR == "mobile") {
                        $(".resetpassword_tel~.point").text(ret.info).addClass("cur");
                    } else {
                        $("#fogetpassowrd_point").text(ret.info).addClass("cur");
                    }
                }
            }
        });
    }

    <%--提交用户信息--%>
    function submitUserinfo() {
        var password = $(".resetpassword_setpassword").val();
        $("input[name='password']").val(createPassword(password, password));
        $.ajax({
            url: '${basePath}v2/forget/fogetpassword',
            type: 'POST',
            data: $(".resetpassword_form").serialize(),
            error: function (response) {
                $errorMsg(response);
            },
            success: function (ret) {
                if (ret.result) {
                    $("#GC_childinfo_remove").show();
                } else {
                    if (ret.ERROR == "smscode") {
                        $(".resetpassword_telcode~.point").text(ret.info).addClass("cur");
                    } else if (ret.ERROR == "imgcode") {
                        $(".resetpassword_imagecode~.point").text(ret.info).addClass("cur");
                    } else if (ret.ERROR == "username") {
                        $(".resetpassword_username~.point").text(ret.info).addClass("cur");
                    } else if (ret.ERROR == "mobile") {
                        $(".resetpassword_tel~.point").text(ret.info).addClass("cur");
                    } else {
                        $("#fogetpassowrd_point").text(ret.info).addClass("cur");
                    }
                }
            }
        });
    }
    //点击获取短信验证码
    var resettimer;
    var resetgetCaptcha=function(){
        $(".resetpassword_telcodeurl").on("click", function(){
            var resetpassword_tel=$(".resetpassword_tel").val();
            var resetpassword_username=$(".resetpassword_username").val();
            var resetpassword_imagecode=$(".resetpassword_imagecode").val();
            if(resetpassword_tel==""){
                $(".resetpassword_tel~.point").text("请输入手机号码").addClass("cur");

            }else if(!(regusertel.test(resetpassword_tel))){
                $(".resetpassword_tel~.point").text("请正确输入11位手机号码").addClass("cur");

            }else if(resetpassword_username==""){
                $(".resetpassword_username~.point").text("请输入用户名").addClass("cur");

            }else if(!(regusername.test(resetpassword_username))){
                $(".resetpassword_username~.point").text("请输入5-20位数字、字母或下划线").addClass("cur");

            }else if(resetpassword_imagecode==""){
                $(".resetpassword_imagecode~.point").text("验证码不能为空").addClass("cur");

            }else if(regusertel.test(resetpassword_tel) && regusername.test(resetpassword_username) && resetpassword_imagecode!=""){
                if(!$(".resetpassword_telcodeurl").hasClass("cur")){
                    $(".resetpassword_telcodeurl").text("重新发送（60s）").addClass("cur");
                    $(".resetpassword_telcodeurl").unbind("click");
                    var second=0;
                    resettimer=setInterval(function(){
                        if(second<60){
                            $(".resetpassword_telcodeurl").text("重新发送（"+(60-second)+"s）");
                            second++;
                        }else if(second>=60){
                            clearInterval(resettimer);
                            second=0;
                            $(".resetpassword_telcodeurl").text("获取短信验证码").removeClass("cur");
                            resetgetCaptcha();
                        }
                    }, 1000);

                    /*获取短信验证码*/
                    getsmscode();
                }
            }
        });
    };

    resetgetCaptcha();
</script>